<?
include_once('config.php');
include_once('model/users.php');
include_once('model/friends.php');
include_once('model/friend_requests.php');

	try{
		delete_account(Session::user()->id);
		Session::stop();
		header("Location: login.php");
	}
	catch(Exception $e){
		Session::set_error($e->getMessage());
	}	
	header("Location: index.php");

function delete_account($user_id){
	//delete user
	Users::delete_user($user_id);
	
	//delete friends
	Friends::delete_friendships($user_id);
	
	//delete friend requests
	FriendRequests::delete_friend_requests($user_id);
}
?>